import axios from "axios";
// let baseUrl='http://127.0.0.1:3000/api/'
let baseUrl='http://127.0.0.1:3000/api'
axios.defaults.baseURL = baseUrl;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
// 请求拦截
let AUTH_TOKEN=window.localStorage.getItem('myToken') ||''

axios.interceptors.request.use(function (config) {
    // console.log(config);
    config. baseURL=baseUrl
    config.headers['Authorization'] = AUTH_TOKEN; // 在发送请求之前在请求头配置token 
    return config;
    }, function (error) {
      // Do something with request error
      return Promise.reject(error);
    });

    // 响应拦截
axios.interceptors.response.use(function (response) {
    // Do something with response data
    // console.log(response);   
    return response.data;

  }, function (error) {
    // Do something with response error
    return Promise.reject(error);
  });

  // 登录请求
// export let getLogin=(params)=>axios.post('/user/login',params);
export let getLogin=(params)=>axios.post('/user/login',params);
//注册
export let getRegistered = (params) => axios.post("/user/register",params);
//商品
export let getShop = (params)=>axios.get('/shop',params)

// 轮播图
// export let getHomeSwiper=(params)=>axios.get('/home/swiper');

// 根据城市请求首页房源
export let getHomeHouse = (params) => axios.post('/house', params)


// 获取房子详情页信息
export let getHouseDetails = (params) => axios.get(`/house/detail/${params}`)

// 热门城市列表获取
export let getHotCity = (params) => axios.get('/house/hotcity', params)

// 根据信息搜索房源
export let getAreaHouse = (params) => axios.post('/house/search', params)

// 获取筛选页特色信息
export let getFeature = () => axios.get('/house/filter')

// 服务页数据接口
//获取保洁家修搬家信息
export let getClean = (params) => axios.get(`/life/sev/cleaning`)
export let getRepair = (params) => axios.get(`/life/sev/repair`)
export let getMove = (params) => axios.get(`/life/sev/move`)


// 商城页数据接口
// 新品上市
export let getProduct = (params) => axios.get(`/shop/newGoods/`, params)

// 卧室
export let getBedroom = ({ id }) => axios.get(`/shop/category/${id}`)

// 卧室储物
export let getStorage = (params) => axios.get(`/shop/roomStorage`, { params })

// 二手商城
export let getSecondMall = (params) => axios.get(`/shop/secondMall/`, params)

// 添加收藏
export let getAddCollect = (params) => axios.post(`/shop/add_collection`, params)

// 添加购物车
export let getAddCart = (params) => axios.post(`/shop/add_cart`, params)


// 获取购物车数据
export let getCart = (params) => axios.get(`/shop/cart/${params}`)

// 删除购物车中商品
export let getDeleteCart = (params) => axios.delete(`/shop/delete_cart/${params.uid}/${params.gid}`)

// 获取收藏列表
export let getCollect = (params) => axios.get(`/shop/collection/${params}`)

// 取消商品收藏
export let getDeleteCollect = (params) => axios.delete(`/shop/cancel_collection/${params.uid}/${params.gid}`)

// 更新订单状态
export let getOrderStateChange = (params) => axios.post(`/shop/order_pay`, params)

// 获取已支付订单商品id
export let getOrder = (params) => axios.get('/shop/order_id', {params})

// 获取已支付商品列表
export let getOrderList = (params) => axios.get('/shop/order_list', {params})

//收藏
export let getCollection = (params) => axios.get(`/user/collection`, { params })
export let getShopCollection = (params) => axios.get(`/shop/collection/${params}`)